﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="sooritakanne_kandesisuv2", Namespace="http://kis.x-road.eu/", Target=typeof(SooritakanneKandesisuv2))]
    public class SooritakanneKandesisuv2Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected SooritakanneKandesisuv2 clazz;
        
        public SooritakanneKandesisuv2Serializer(SooritakanneKandesisuv2 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Registrikood!=null) {
                Writer.WriteStartElement("registrikood");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Registrikood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Pohitegevusala!=null) {
                Writer.WriteStartElement("pohitegevusala");
                global::Xtee.Core.SerializationMetadata metaPohitegevusala = this.GetMetaData(clazz.Pohitegevusala);
                if (ShouldWriteTypeAttribute(typeof(global::Kis.Xroad.Eu.Menetlus), clazz.Pohitegevusala.GetType())) {
                    Writer.WriteTypeAttribute(metaPohitegevusala.TypeQualifiedName.Namespace, metaPohitegevusala.TypeQualifiedName.Name);
                }
                var pohitegevusalaSerializer = metaPohitegevusala.NewSerializer(clazz.Pohitegevusala);
                pohitegevusalaSerializer.WriteXmlAttributes(Writer);
                pohitegevusalaSerializer.WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Lisategevusala!=null) {
                Writer.WriteStartElement("lisategevusala");
                Writer.WriteString(clazz.Lisategevusala.ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "registrikood")) {
                goto registrikood;
            }
            else {
                if ((Reader.LocalName == "pohitegevusala")) {
                    goto pohitegevusala;
                }
                else {
                    if ((Reader.LocalName == "lisategevusala")) {
                        goto lisategevusala;
                    }
                    else {
                        return;
                    }
                }
            }
        registrikood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_kandesisuv2>registrikood");
            }
            clazz.Registrikood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("registrikood")).Value;
            goto START;
        pohitegevusala:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_kandesisuv2>pohitegevusala");
            }
            global::Xtee.Core.SerializationMetadata metaPohitegevusala = this.GetMetaData<global::Kis.Xroad.Eu.Menetlus>(Reader, "Menetlus", "http://kis.x-road.eu/");
            clazz.Pohitegevusala = metaPohitegevusala.NewEntity<global::Kis.Xroad.Eu.Menetlus>();
            if ((Reader.IsEmptyElement == false)) {
                var pohitegevusalaSerializer = metaPohitegevusala.NewSerializer(clazz.Pohitegevusala);
                pohitegevusalaSerializer.ReadXmlAttributes(Reader);
                Reader.ReadStartElement("pohitegevusala");
                pohitegevusalaSerializer.ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        lisategevusala:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_kandesisuv2>lisategevusala");
            }
            clazz.Lisategevusala = new global::Kis.Xroad.Eu.WorkDay(Reader.ReadElementString("lisategevusala"));
            goto START;
        }
    }
}
